package conn;

import java.sql.*;

public class Conn {

    public static final String url = "jdbc:sqlserver://localhost:1433;DatabaseName=Graduate";
    public static final String name = "sa";
    public static final String pwd = "qzi128850986";

    public static Connection getConnection() {

        Connection conn = null;
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            conn = DriverManager.getConnection(url, name, pwd);
        }catch(ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
        return conn;

    }

    public static void release(Connection conn, Statement stmt) {

        if(conn != null) {
            try {
                conn.close();
            }catch(SQLException e) {
                e.printStackTrace();
            }
            conn = null;
        }

        if(stmt != null) {
            try {
                stmt.close();
            }catch(SQLException e){
                e.printStackTrace();
            }
            stmt = null;
        }

    }

    public static void release(Connection conn, Statement stmt, ResultSet rs) {

        if(rs != null) {
            try {
                rs.close();
            }catch(SQLException e) {
                e.printStackTrace();
            }
            rs = null;
        }
        release(conn, stmt);
    }
}
